<template>
  <div>
    <router-link v-show="flag" tag="div" to="/" class="abs">
      <div class="iconfont">&#xe623;</div>
    </router-link>
    <div class="fix" v-show="!flag" :style="opacitystyle">
      景点详情
      <router-link to="/" >
        <div class="iconfont back">&#xe623;</div>
      </router-link>
    </div>
  </div>
</template>

<script>
export default {
  name: "DetailHeader",
  data() {
      return {
          flag: true,
          opacitystyle: {
              opacity: 0
          }
      }
  },
  methods: {
      handlescroll() {
          console.log('scroll');
        const top = document.documentElement.scrollTop
        if(top > 60) {
            let opacity = top / 140
            opacity = opacity > 1 ? 1 : opacity
            this.opacitystyle = {opacity}
            this.flag = false
        }else {
            this.flag = true
        }
      }

  },
  activated() {
      window.addEventListener('scroll', this.handlescroll)
  },
  deactivated() {
    window.removeEventListener('scroll', this.handlescroll)
  }
};
</script>

<style scoped>
.abs {
  position: absolute;
  left: 0.2rem;
  top: 0.2rem;
  width: 0.8rem;
  height: 0.8rem;
  line-height: 0.8rem;
  text-align: center;
  color: #fff;
  border-radius: 0.4rem;
  background: rgba(0, 0, 0, 0.4);
}
.fix {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 0.86rem;
  line-height: 0.86rem;
  text-align: center;
  font-size: 0.36rem;
  color: #fff;
  background: #00bcd4;
}
.back {
  position: absolute;
  left: 0;
  top: 0;
  width: .7rem;
  color: #fff;
}
</style>